package com.hq.door.dto;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import com.hq.door.pojo.TTeacher;
import com.hq.door.util.DateUtil;
import com.hq.door.util.StrUtil;

/**
 * @author Administrator
 *
 */
/**
 * @author Administrator
 *
 */
public class TeacherDto {
	
	//教师信息
	private Integer id;	//教师id，主键
	private String teacherName;	//教师姓名
	private String teacherAccount;//教师账号
	private String teacherPassword;//账号密码
	private String teacherCode;	//教师编号
	private String teacherMobile;	//教师手机号
	
	private String teacherWXID;		//教师微信ID
	private String address;
	private String modifyBy="";	//修改人
	private String modifyTime;	//修改时间
	
	public TeacherDto(){};
	


	/**
	 * 对应Excel数据导入
	 * @param teacherName
	 * @param teacherMobile
	 * @param teacherCode
	 * @param address
	 * @param modifyBy
	 */
	public TeacherDto(String teacherName,String teacherMobile,
			String teacherCode, String address,String modifyBy) {
		this.teacherName = teacherName;
		this.teacherCode = teacherCode;
		this.teacherMobile = teacherMobile;
		this.address = address;
		this.modifyBy = modifyBy;
	}
	
	public TeacherDto(Integer id, String teacherName, String teacherCode,
			String teacherMobile, String address, String modifyBy,
			String modifyTime) {
		this.id = id;
		this.teacherName = teacherName;
		this.teacherCode = teacherCode;
		this.teacherMobile = teacherMobile;
		this.address = address;
		this.modifyBy = modifyBy;
		this.modifyTime = modifyTime;
	}
	
	public TeacherDto(String teacherName, String teacherCode,
			String teacherMobile, String address, String modifyBy,
			String modifyTime) {
		this.teacherName = teacherName;
		this.teacherCode = teacherCode;
		this.teacherMobile = teacherMobile;
		this.address = address;
		this.modifyBy = modifyBy;
		this.modifyTime = modifyTime;
	}



/*
 * boolean flag，无用变量标识，用来区分重载
 */
	public TeacherDto(String teacherName, String teacherAccount,
			String teacherPassword, String teacherCode, String teacherMobile,boolean flag) {
		super();
		this.teacherName = teacherName;
		this.teacherAccount = teacherAccount;
		this.teacherPassword = teacherPassword;
		this.teacherCode = teacherCode;
		this.teacherMobile = teacherMobile;
	}



	@Override
	public String toString() {
		return "TeacherDto [id=" + id + ", teacherName=" + teacherName
				+ ", teacherAccount=" + teacherAccount + ", teacherPassword="
				+ teacherPassword + ", teacherCode=" + teacherCode
				+ ", teacherMobile=" + teacherMobile + ", teacherWXID="
				+ teacherWXID + ", address=" + address + ", modifyBy="
				+ modifyBy + ", modifyTime=" + modifyTime + "]";
	}



	/**
	 * 数据库对象 pojo转换成自定义家长类
	 * @param 	
	 * @return
	 */
	public static TeacherDto writeTeacher(TTeacher tt){
		TeacherDto dto = null;
		if(tt!=null){
			dto = new TeacherDto();
			dto.setId(tt.getId());
			dto.setTeacherName(StrUtil.obj2Str(tt.getName()));
			dto.setTeacherCode(StrUtil.obj2Str(tt.getCode()));
			dto.setTeacherMobile(StrUtil.obj2Str(tt.getMobile()));
			dto.setTeacherWXID(StrUtil.obj2Str(tt.getWeixinId()));
			dto.setAddress("");
			dto.setModifyTime(tt.getModifiedTime()==null?"":DateUtil.time2Str(tt.getModifiedTime().getTime(), DateUtil.ymdHms));
			dto.setModifyBy("root");//有问题，现在时写死了
			dto.setTeacherAccount(StrUtil.obj2Str(tt.getAccount()));
		
		}
		return dto;
	}
	
	/**
	 * 转换成数据库对象 pojo
	 * @param parent	
	 * @return
	 */
	public static TTeacher readTeacher(TeacherDto dto){
		TTeacher tt = null;
		if(dto!=null){
			tt = new TTeacher();
			tt.setId(dto.getId());
			tt.setName(dto.getTeacherName());
			tt.setCode(dto.getTeacherCode());
			tt.setMobile(dto.getTeacherMobile());
			tt.setPassword(dto.getTeacherPassword());
			tt.setModifiedTime(new Timestamp((new Date()).getTime()));
			tt.setModifiedBy(StrUtil.str2Int(dto.getModifyBy()));
			if(dto.getTeacherAccount()!=null){
				tt.setAccount(dto.getTeacherAccount());
			}
		}
		return tt;
	}
	
//	/**
//	 * 转换成数据库对象 pojo，编辑单个老师信息
//	 * @param parent	
//	 * @return
//	 */
//	public static TTeacher readTeacherOfUpdateOneMsg(TeacherDto dto){
//		TTeacher tt = null;
//		if(dto!=null){
//			tt = new TTeacher();
//			tt.setId(dto.getId());
//			tt.setName(dto.getTeacherName());
//			tt.setCode(dto.getTeacherCode());
//			tt.setMobile(dto.getTeacherMobile());
////			tt.setPassword(dto.getTeacherPassword());
//			tt.setModifiedTime(new Timestamp((new Date()).getTime()));
//			tt.setModifiedBy(StrUtil.str2Int(dto.getModifyBy()));
//		}
//		return tt;
//	}
	
	/**
	 * 查询多条教师信息
	 * @return
	 */
	public static List<TeacherDto> writeTeacher(List<TTeacher> tts){
		List<TeacherDto> dtos = new ArrayList<TeacherDto>();
		for(TTeacher tt : tts){
			TeacherDto dto = writeTeacher(tt);
			dtos.add(dto);
		}
		return dtos;
	}
	/**
	 * 转换数据为数据库对象
	 * @return
	 */
	public static List<TTeacher> readTeacher(List<TeacherDto> dtos){
		List<TTeacher> tts = new ArrayList<TTeacher>();
		for(TeacherDto dto : dtos){
			TTeacher tt = readTeacher(dto);
			tts.add(tt);
		}
		return tts;
	}
	
	public static Teacher writeMajor(TTeacher tTeacher){
		Teacher teacher = new Teacher();
	    if (tTeacher != null){
	    	teacher.setId(tTeacher.getId());
	    	teacher.setName(tTeacher.getName());
	    	teacher.setMobile(tTeacher.getMobile());
	    	teacher.setPassword(tTeacher.getPassword());
	    	teacher.setCode(tTeacher.getCode());
	    	teacher.setWeixinId(tTeacher.getWeixinId());
	    	teacher.setModifiedBy(tTeacher.getModifiedBy());
	    	teacher.setAccount(tTeacher.getAccount());
	    }
	    return teacher;
    }
	
	
	public static Teacher[] writeMajor(Collection teachers){
		List list = new ArrayList();
		if (teachers != null){
			Iterator iterator = teachers.iterator();
            while (iterator.hasNext())
            {
                list.add(writeMajor((TTeacher) iterator.next()));
            }
		}
		Teacher[] array = new Teacher[list.size()]; 
		return (Teacher[]) list.toArray(array);
	}

	public static TTeacher readMajor(Teacher teacher){
		TTeacher tTeacher = new TTeacher();
	    if (teacher != null){
	    	tTeacher.setId(teacher.getId());
	    	tTeacher.setName(teacher.getName());
	    	tTeacher.setMobile(teacher.getMobile());
	    	tTeacher.setCode(teacher.getCode());
	    	tTeacher.setPassword(teacher.getPassword());
	    	tTeacher.setWeixinId(teacher.getWeixinId());
	    	tTeacher.setModifiedBy(teacher.getModifiedBy());
	    	
	    }
	    return tTeacher;
    }

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getTeacherName() {
		return teacherName;
	}

	public void setTeacherName(String teacherName) {
		this.teacherName = teacherName;
	}

	public String getTeacherCode() {
		return teacherCode;
	}

	public void setTeacherCode(String teacherCode) {
		this.teacherCode = teacherCode;
	}

	public String getTeacherMobile() {
		return teacherMobile;
	}

	public void setTeacherMobile(String teacherMobile) {
		this.teacherMobile = teacherMobile;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getModifyBy() {
		return modifyBy;
	}

	public void setModifyBy(String modifyBy) {
		this.modifyBy = modifyBy;
	}

	public String getModifyTime() {
		return modifyTime;
	}

	public void setModifyTime(String modifyTime) {
		this.modifyTime = modifyTime;
	}

	public String getTeacherWXID() {
		return teacherWXID;
	}

	public void setTeacherWXID(String teacherWXID) {
		this.teacherWXID = teacherWXID;
	}
	public String getTeacherAccount() {
		return teacherAccount;
	}

	public void setTeacherAccount(String teacherAccount) {
		this.teacherAccount = teacherAccount;
	}

	public String getTeacherPassword() {
		return teacherPassword;
	}

	public void setTeacherPassword(String teacherPassword) {
		this.teacherPassword = teacherPassword;
	}
}
